﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Expect.Core.Config;
using System.Globalization;

namespace Expect.Core.CodeGen
{
    /// <summary>
    /// Unit test framework targeted by codegen
    /// </summary>
    public enum UnitTestProviders
    {
        /// <summary>
        /// No test framework
        /// </summary>
        None,
        /// <summary>
        /// MsTest framework
        /// </summary>
        MsTest,
        /// <summary>
        /// NUnit framework
        /// </summary>
        NUnit
    }    

    /// <summary>
    /// Code generation configuration
    /// </summary>
    public class CodeGenConfig
    {
        private UnitTestProviders framework = UnitTestProviders.MsTest;

        /// <summary>
        /// Target unit test framework
        /// </summary>
        public UnitTestProviders Framework
        {
            get
            {
                return this.framework;
            }
            set
            {
                this.framework = value;
            }
        }

        /// <summary>
        /// Full name of the base class for specifications container
        /// </summary>
        public string ContainerBaseClass { get; set; }

        /// <summary>
        /// Get CodeGen configuration
        /// </summary>
        /// <param name="content">config file content</param>
        /// <returns></returns>
        public static CodeGenConfig FromContent(string content)
        {
            return CodeGenConfig.FromConfiguration(ExpectConfigurationSection.ReadFromContent(content));
        }

        /// <summary>
        /// Get CodeGen configuration
        /// </summary>
        /// <param name="section">global configuration</param>
        /// <returns></returns>
        public static CodeGenConfig FromConfiguration(ExpectConfigurationSection section)
        {
            var res = new CodeGenConfig();
            if (section != null && section.CodeGen != null)
                res.ContainerBaseClass = section.CodeGen.ContainerBaseClass;

            if (section == null)
            {
                res.Framework = UnitTestProviders.MsTest;

                return res;
            }

            if (string.Compare(section.CodeGen.UnitTestProvider, "NUnit", true) == 0)
            {
                res.Framework = UnitTestProviders.NUnit;
            }
            else
            {
                res.framework = UnitTestProviders.MsTest;
            }
            
            return res;
        }
    }
}
